<template>
  <div class="app-container">
    <div>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
          >新增
          </el-button>
        </el-col>
      </el-row>
    </div>

    <!--表格内容-->
    <el-table v-loading="loading" :data="storelist" @selection-change="getStoresList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="店家编号" align="center" prop="storeId" />
      <el-table-column label="店家名称" align="center" prop="storeName" :show-overflow-tooltip="true" />
      <el-table-column label="店家地址" align="center" prop="storeAddress" :show-overflow-tooltip="true" />
      <el-table-column label="联系电话" align="center" prop="contactPhone" :show-overflow-tooltip="true" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:dict:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:dict:remove']"
          >删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getStoresList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="店家名称" prop="storeName">
          <el-input v-model="form.storeName" placeholder="请输入店家名称"/>
        </el-form-item>
        <el-form-item label="店家地址" prop="storeAddress">
          <el-input v-model="form.storeAddress" placeholder="请输入店家地址"/>
        </el-form-item>
        <el-form-item label="联系电话" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="请输入电话名称"/>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script >
import {addStore, listStores} from "@/api/human/store";

export default {
  name: 'Store',
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      action: "",
      open: false,
      // 遮罩层
      loading: true,
      //店家信息
      storelist:[],
      total:0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      form: {
        storeName: '',
        storeAddress: '',
        contactPhone: '',
      },
    }
  },
  created() {
    this.getStoresList()
  },
  methods: {
    //获取店铺信息
    async getStoresList(){
      this.loading = true
      const data = await listStores({},this.queryParams);
      this.total = data.total;
      this.storelist = data.rows;
      this.loading = false
      /*this.storelist.push({
        storeId: '1',
        storeName: '店铺名称1',
        storeAddress: '店铺地址1',
        contactPhone: '1234567890',
      })*/
    },
    // 新增商店
    async handleAdd() {
      this.title = '新增店铺';
      this.action = 'add';
      this.open = true;
    },
    //表单重置
    reset() {
      this.form = {
        storeName: '',
        storeAddress: '',
        contactPhone: '',
      }
    },
    // 提交表单
    async submitForm() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          if (this.action === 'add') {
            // 新增逻辑
            const data = await addStore(this.form);
            console.log(data);
            this.$modal.msgSuccess(data.msg);
            this.open = false
            await this.getStoresList();
          }
        }
      })
    },
    cancel() {
      this.open = false;
      this.reset();
    }
  }
}
</script>


